package com.itheima.stock.controller;


import com.itheima.stock.pojo.domain.*;
import com.itheima.stock.pojo.vo.req.PageResult;
import com.itheima.stock.pojo.vo.resp.R;
import com.itheima.stock.service.StockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Api("/api/quot")
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    private StockService stockService;


    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> innerIndexAll() {
        return stockService.innerIndexAll();
    }

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/external/index")
    public R<List<OuterMarketDomain>> outerIndexAll() {
        return stockService.outerIndexAll();
    }

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<BlockRtDomain>> BlockRtAll() {
        return stockService.BlockRtAll();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "pageSize", value = "")
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult<RtDomain>> RtPage(@RequestParam(value = "page", required = false, defaultValue = "1") String page,
                                          @RequestParam(value = "pageSize", required = false, defaultValue = "20") String pageSize) {
        return stockService.RtPage(page, pageSize);
    }

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<RtDomain>> RtAll() {
        return stockService.RtAll();
    }

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map<String, List>> UpDownCount() {
        return stockService.UpDownCount();
    }

    /**
     * 导出指定页码的最新股票信息
     * @param page 当前页
     * @param pageSize 每页大小
     */

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "导出指定页码的最新股票信息", notes = "导出指定页码的最新股票信息", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void exportRtInfo(@RequestParam(value = "page", required = false, defaultValue = "1") String page,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "20") String pageSize,
                             HttpServletResponse response) {
        stockService.exportRtInfo(page,pageSize,response);
    }

    /**
     * 股票成交量对比
     * @return
     */

    @ApiOperation(value = "股票成交量对比", notes = "股票成交量对比", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List>> stockTradeVol4InnerMarket(){
        return stockService.stockTradeVol4InnerMarket();
    }

    /**
     * 个股分时涨跌幅度统计
     * @return
     */

    @ApiOperation(value = "个股分时涨跌幅度统计", notes = "个股分时涨跌幅度统计", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDown(){
        return stockService.getStockUpDown();
    }


    /**
     *个股分时K线行情
     * @param code 股票代码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票代码", required = true)
    })
    @ApiOperation(value = "个股分时K线行情", notes = "个股分时K线行情", httpMethod = "GET")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> stockScreenTimeSharing (@RequestParam("code") String code){
        return stockService.stockScreenTimeSharing(code);
    }

    /**
     * 个股日K线详情
     * @param code 股票代码
     * @return
     */

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票代码", required = true)
    })
    @ApiOperation(value = "个股日K线详情", notes = "个股日K线详情", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getDayKLinData(@RequestParam("code") String code){
        return stockService.getDayKLinData(code);
    }
    @GetMapping("/stock/search")
    public R<List<Map>> searchStock(@RequestParam("searchStr") String searchStr){
        return stockService.searchStock(searchStr);
    }
    @GetMapping("/stock/describe")
    public R<DescribeDomain> getDescribe(@RequestParam("code") String code){
        return stockService.getDescribe(code);
    }
    @GetMapping("/stock/screen/weekkline")
    public R<List<WeekklineDomain>> getWeekkline(@RequestParam("code") String code){
        return stockService.getWeekkline(code);
    }
    @GetMapping("/stock/screen/second/detail")
    public R<DetailDomain> getRtDetail(@RequestParam("code") String code){
        return stockService.getRtDetail(code);
    }

    @GetMapping("/stock/screen/second")
    public R<List<TradeDomain>> getRtTrade(@RequestParam("code") String code){
        return stockService.getRtTrade(code);
    }


}
